#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;

struct Card {
    enum class Suit {
        CLUBS = 0,
        DIAMONDS,
        HEARTS,
        SPADES,
    } suit;
    enum class Rank {
        ONE = 1,
        TWO = 2,
        THREE,
        FOUR,
        FIVE,
        SIX,
        SEVEN,
        EIGHT,
        NINE,
        TEN,
        JACK,
        QUEEN,
        KING,
        ACE,
    } rank;
    Card() = default;
    Card(string s) {
        static const string suits = "CDHS";
        static const string ranks = "23456789TJQKA";
        suit = static_cast<Suit>(suits.find(s[1]));
        rank = static_cast<Rank>(ranks.find(s[0]) + 2);
    }
    bool operator<(const Card& other) const { return rank < other.rank; }
    bool operator==(const Card& other) const { return rank == other.rank; }
    bool operator>(const Card& other) const { return rank > other.rank; }
    ~Card() = default;
};

struct HandCard {
    enum class CardType {
        HIGH_CARD = 0,      // No pair, no flush, no straight.
        ONE_PAIR,
        TWO_PAIRS,
        THREE_OF_A_KIND,
        STRAIGHT,
        FLUSH,
        FULL_HOUSE,
        FOUR_OF_A_KIND,
        STRAIGHT_FLUSH,     // All cards are consecutive values of same suit.
        ROYAL_FLUSH,        // Ten, Jack, Queen, King, Ace, in same suit.
    } type;
    vector<Card::Rank> ranks;
    array<Card, 5> cards;

    ~HandCard() = default;
    HandCard(Card a, Card b, Card c, Card d, Card e): cards{a, b, c, d, e} {
        sort(cards.begin(), cards.end());
        type = get_type();
        switch (type)
        {
        case CardType::STRAIGHT_FLUSH:
        case CardType::ROYAL_FLUSH:
            ranks = {cards[0].rank};
            break;
        case CardType::FOUR_OF_A_KIND:
            if (cards[0].rank == cards[1].rank) {
                ranks = {cards[0].rank, cards[4].rank};
            } else {
                ranks = {cards[4].rank, cards[0].rank};
            }
            break;
        case CardType::FULL_HOUSE:
            if (cards[0].rank == cards[1].rank && cards[1].rank == cards[2].rank) {
                ranks = {cards[0].rank, cards[4].rank};
            } else {
                ranks = {cards[3].rank, cards[1].rank};
            }
            break;
        case CardType::FLUSH:
        case CardType::STRAIGHT:
            ranks = {cards[4].rank};
            break;
        case CardType::THREE_OF_A_KIND:
            if (cards[0].rank == cards[1].rank && cards[1].rank == cards[2].rank) {
                ranks = {cards[0].rank, cards[4].rank, cards[3].rank};
            } else if (cards[1].rank == cards[2].rank && cards[2].rank == cards[3].rank) {
                ranks = {cards[1].rank, cards[4].rank, cards[0].rank};
            } else {
                ranks = {cards[2].rank, cards[1].rank, cards[0].rank};
            }
            break;
        case CardType::TWO_PAIRS:
            if (cards[0].rank == cards[1].rank && cards[2].rank == cards[3].rank) {
                ranks = {cards[2].rank, cards[0].rank, cards[4].rank};
            } else if (cards[0].rank == cards[1].rank && cards[3].rank == cards[4].rank) {
                ranks = {cards[3].rank, cards[0].rank, cards[2].rank};
            } else {
                ranks = {cards[4].rank, cards[2].rank, cards[0].rank};
            }
            break;
        case CardType::ONE_PAIR:
            if (cards[0].rank == cards[1].rank) {
                ranks = {cards[0].rank, cards[4].rank, cards[3].rank, cards[2].rank};
            } else if (cards[1].rank == cards[2].rank) {
                ranks = {cards[1].rank, cards[4].rank, cards[3].rank, cards[0].rank};
            } else if (cards[2].rank == cards[3].rank) {
                ranks = {cards[2].rank, cards[4].rank, cards[1].rank, cards[0].rank};
            } else {
                ranks = {cards[3].rank, cards[2].rank, cards[1].rank, cards[0].rank};
            }
            break;
        case CardType::HIGH_CARD:
            ranks = {cards[4].rank, cards[3].rank, cards[2].rank, cards[1].rank, cards[0].rank};
            break;
        default:
            break;
        }
    }
    bool operator>(const HandCard& other) const {
        if (type > other.type) return true;
        if (type < other.type) return false;
        for (auto i = 0; i < ranks.size(); ++i) {
            if (ranks[i] > other.ranks[i]) return true;
            if (ranks[i] < other.ranks[i]) break;
        }
        return false;
    }
    string to_string() {
        const string str_rank = "123456789TJQKA";
        const string str_suit = "CDHS";
        string result;
        for (const auto& card : cards) {
            result += str_rank[static_cast<int>(card.rank)-1];
            result += str_suit[static_cast<int>(card.suit)];
            result += ' ';
        }
        return result;
    }
private:
    CardType get_type() {
        bool flush = is_flush();
        bool straight = is_straight();
        if (flush && straight) return cards[0].rank == Card::Rank::TEN ? CardType::ROYAL_FLUSH : CardType::STRAIGHT_FLUSH;
        if (is_four_of_a_kind()) return CardType::FOUR_OF_A_KIND;
        if (is_full_house()) return CardType::FULL_HOUSE;
        if (flush) return CardType::FLUSH;
        if (straight) return CardType::STRAIGHT;
        if (is_three_of_a_kind()) return CardType::THREE_OF_A_KIND;
        if (is_two_pairs()) return CardType::TWO_PAIRS;
        if (is_one_pair()) return CardType::ONE_PAIR;
        return CardType::HIGH_CARD;
    }
    bool is_flush() {
        return cards[0].suit == cards[1].suit && cards[1].suit == cards[2].suit &&
               cards[2].suit == cards[3].suit && cards[3].suit == cards[4].suit;
    }
    bool is_straight() {
        // Check for Ace low straight (A, 2, 3, 4, 5)
        if (cards[0].rank == Card::Rank::TWO && cards[1].rank == Card::Rank::THREE &&
            cards[2].rank == Card::Rank::FOUR && cards[3].rank == Card::Rank::FIVE &&
            cards[4].rank == Card::Rank::ACE) {
            cards[4].rank = Card::Rank::ONE;
            sort(cards.begin(), cards.end());
        }

        return int(cards[0].rank) + 1 == int(cards[1].rank) && int(cards[1].rank) + 1 == int(cards[2].rank) &&
               int(cards[2].rank) + 1 == int(cards[3].rank) && int(cards[3].rank) + 1 == int(cards[4].rank);
    }
    bool is_four_of_a_kind() {
        return (cards[0] == cards[1] && cards[1] == cards[2] && cards[2] == cards[3]) ||
               (cards[1] == cards[2] && cards[2] == cards[3] && cards[3] == cards[4]);
    }
    bool is_full_house() {
        return (cards[0] == cards[1] && cards[1] == cards[2] && cards[3] == cards[4]) ||
               (cards[0] == cards[1] && cards[2] == cards[3] && cards[3] == cards[4]);
    }
    bool is_three_of_a_kind() {
        return (cards[0] == cards[1] && cards[1] == cards[2]) ||
               (cards[1] == cards[2] && cards[2] == cards[3]) ||
               (cards[2] == cards[3] && cards[3] == cards[4]);
    }
    bool is_two_pairs() {
        return (cards[0] == cards[1] && cards[2] == cards[3]) ||
               (cards[0] == cards[1] && cards[3] == cards[4]) ||
               (cards[1] == cards[2] && cards[3] == cards[4]);
    }
    bool is_one_pair() {
        return (cards[0] == cards[1]) || (cards[1] == cards[2]) ||
               (cards[2] == cards[3]) || (cards[3] == cards[4]);
    }
};

int main() {
    int ans = 0;
    ifstream file("54.txt");
    string line;
    while (getline(file, line)) {
        auto p1 = HandCard({line.substr(0, 2)}, {line.substr(3, 2)}, {line.substr(6, 2)}, {line.substr(9, 2)}, {line.substr(12, 2)});
        auto p2 = HandCard({line.substr(15, 2)}, {line.substr(18, 2)}, {line.substr(21, 2)}, {line.substr(24, 2)}, {line.substr(27, 2)});
        ans += (p1 > p2);
    }
    cout << ans << endl;
    file.close();
}